package com.bdsy.system.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.bdsy.common.utils.JsonUtils;
import com.bdsy.common.utils.ValidateUtils;
import com.bdsy.system.dao.UserMapper;
import com.bdsy.system.model.User;
import com.bdsy.system.service.UserService;

/**
 * ClassName:UserServiceImpl
 * Description: TODO 添加描述.
 * @author   Administrator
 * @version  
 * @since    JDK 1.8
 */

@Service("userService")
public class UserServiceImpl implements UserService{

    @Autowired
    UserMapper userMapper;
    
    @Override
	public List<String> queryAllPerms(String userId){
		List<String> list = userMapper.queryAllPerms(userId);
		return list;
	}
    
    @Override
	public User getUsername(String loginame) {
		User user = userMapper.selectLoginame(loginame);
		return user;
	}
	
	@Override
	public User login(String username ,char[] password) {
		if(username !=null && username.trim().length()>0){
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("username", username);
		map.put("password", password);
		User user = userMapper.selectByNamePwd(map);
		return user;
		}
		return null;
	}
	
	@Override
	public List<Map> getUserList(){
		List<Map> list = userMapper.selectUserList();
		return list;
	} 
	
	public boolean addUser(User user){
		int result = 0;
		result = userMapper.insert(user);
		return result>0?true:false;
	}
	
	public boolean updateUser(User user){
		int result = 0;
		result = userMapper.update(user);
		return result>0?true:false;
	}
	
	@Override
	public boolean deleteUserById(List<String> pIds) {
		int result = userMapper.deleteUser(pIds);
		return result>0?true:false;
	}
	
	@Override
	public void updateUserDate(Date lastAccessTime,String uid,String userId) {
		userMapper.updateUserDate(lastAccessTime,uid,userId);
	}
	
	@Override
	public User getUserByUid(String userId){
		User user = userMapper.selectUserById(userId);
		return user;
	}
	
	@Override
	public List<Map> getUserName(){
		List<Map> list = userMapper.selectUserName();
		return list;
	}
	
	@Override
	public User getUserById(String userId){
		User user = userMapper.selectUserById(userId);
		return user;
	}
	
	public String getLoginPasswordById(String userId) {
	
		if(userId != null && userId.trim().length()>0){
		String loginPassword = userMapper.getLoginPasswordById(userId);
		return loginPassword;
		}
		return null;
	}

	@Override
	public boolean updatePassWord(User user) {
		int result = userMapper.updatePassWord(user);
		return result>0?true:false;
	}
	
}

